package com.coco.service.Impl;

import java.sql.SQLException;
import java.util.List;

import com.coco.dao.Impl.UserDaoImpl;
import com.coco.model.User;
import com.coco.service.UserService;

public class UserServiceImpl implements UserService {
	
	private UserDaoImpl userDaoImpl = new UserDaoImpl();
	
	@Override
	public boolean register(User u) throws SQLException{
		String sql = "insert into user values(?,?,?,?,?,?,?,?,?,?,?)";
		Object[] params = new Object[]{u.getUid(),u.getUname(),u.getUpwd(),u.getRealname(),u.getUemail(),
				u.getUtel(),u.getUbirthday(),u.getUgender(),u.getState(),u.getCode(),u.getUintroduce()};
		int count = userDaoImpl.register(sql,params);
		if(count == 1){
			return true;
		}
		return false;
	}

	@Override
	public boolean active(String uid, String code) throws SQLException {
		List<User> list=userDaoImpl.findByOthers("select * from user where uid=? and code=?", uid,code);
		//TODO
		if(list.size()>0){
			return true;
		}
		return false;
			
	}
	
	@Override
	public boolean active1(String uid) throws SQLException {
		String sql = "update user set state=?,code=? where uid=?";
		int count=userDaoImpl.update(sql,"1","null",uid);
		if(count==1){
			return true;
		}
		return false;
			
	}

	@Override
	public boolean findByName(String uname) throws SQLException {
		User u=userDaoImpl.findByName(uname);
		if(u==null){
			return false;
		}
		return true;
			
			
	}

	@Override
	public User login(String uname, String upwd) throws SQLException {
		return userDaoImpl.findByNameAndPwd(uname,upwd);
			
	}

	
}

	